package pers.qianyu.module.image.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.module.core.comm.HttpResult;
import pers.qianyu.module.core.comm.Pagination;
import pers.qianyu.module.core.domain.image.dto.ImageLikeDTO;
import pers.qianyu.module.core.domain.image.query.ImageLikeQuery;
import pers.qianyu.module.core.domain.image.vo.ImageVO;
import pers.qianyu.module.image.service.ImageLikeService;
import pers.qianyu.module.logging.annotation.ControllerLog;
import pers.qianyu.module.logging.enums.BusinessType;

/**
 * @author mizzle rain
 * @since 2021年3月16日 20点17分
 */
@Api(tags = "点赞功能相关接口")
@RequestMapping("/image-serv")
@RestController
public class LikesController {

    @Autowired
    private ImageLikeService imageLikeService;

    @ApiOperation("新增一条点赞信息")
    @ControllerLog(businessType = BusinessType.ADD)
    @PostMapping("/like")
    public HttpResult<?> addLikes(@RequestBody ImageLikeDTO imageLikeDTO) {
        imageLikeService.insert(imageLikeDTO);
        return HttpResult.okWithMessage("点赞成功");
    }

    @ApiOperation("取消点赞")
    @ControllerLog(businessType = BusinessType.DELETE)
    @PostMapping("/cancel_like")
    public HttpResult<?> cancelLikes(@RequestBody ImageLikeDTO imageLikeDTO) {
        imageLikeService.delete(imageLikeDTO);
        return HttpResult.okWithMessage("取消点赞成功");
    }

    @ApiOperation("根据用户ID查询该用户所有点赞的图片")
    @ControllerLog(businessType = BusinessType.QUERY)
    @GetMapping("/likes")
    public HttpResult<Pagination<ImageVO>> queryLikes(ImageLikeQuery imageLikeQuery) {
        Pagination<ImageVO> page = imageLikeService.queryImage(imageLikeQuery);
        return HttpResult.okWithData(page);
    }

}
